<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>试卷上传</title>
    <link rel="stylesheet" type="text/css" href="../plugin/layui/css/layui.css" />
    <script src="/js/jquery-3.5.0.js" type="text/javascript" charset="utf-8"></script>
    <script src="../plugin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script>
        layui.use(['form'], function(){
            var form = layui.form,$=layui.jquery;
        });
        $(document).ready(function () {
            //文件上传
            $("#startUp").click(function () {
                var formData=new FormData();
                var storage=localStorage;
                var token=storage.getItem("token");
                var refreshToken=storage.getItem("refreshToken");
                console.log(token)
                console.log(refreshToken)
                formData.append("grade",$("#grade").val());
                formData.append("paperType",$("#select").val());
                formData.append("filee",$("#filee")[0].files[0]);
                formData.append("refreshToken",refreshToken);
                console.log(formData.get("filee"))
                $.ajax({
                    url:"../paperup/uppaper",
                    type:"post",
                    data:formData,
                    cache:false,
                    processData:false,
                    contentType:false,
                    headers:{
                        refreshToken:refreshToken,
                        token:token
                    },
                    success:function (res) {
                        console.log(res)
                        if(res.code==0){
                            alert("上传成功");
                        }else{
                            alert("系统维护");
                        }
                    }
                })
            });
        })
    </script>
</head>
<body>
    <div style="width: 200px">
        <form class="layui-form" enctype="multipart/form-data">
            <div class="layui-form-item">
                <label class="layui-form-label">年级</label>
                <div class="layui-input-block">
                    <select name="grade" lay-verify="required" id="grade">
                        <option value="">请选择</option>
                        <option value="1">高一</option>
                        <option value="2">高二</option>
                        <option value="3">高三</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">考试类型</label>
                <div class="layui-input-block">
                    <select name="paperType" lay-verify="required" id="select">
                        <option value="">请选择</option>
                        <option value="1">当天作业</option>
                        <option value="2">周末作业</option>
                        <option value="3">寒暑假作业</option>
                        <option value="4">月考</option>
                        <option value="5">期中考</option>
                        <option value="6">期末考</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择文件</label>
                <div class="layui-input-block">
                    <input type="file" name="filee" required  lay-verify="required"  autocomplete="off" class="layui-input" id="filee">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit lay-filter="startUp" id="startUp">开始上传</button>
                </div>
            </div>
        </form>
    </div>
</body>
</html>